<template>
  <div class="PageForm">
    <MyForm v-bind="pageFormConfig" v-model="formData">
      <template #header>
        <!-- <h2>高级检索</h2> -->
      </template>
      <template #footer>
        <div class="footer">
          <el-button :icon="Refresh" @click="handleReset">重置</el-button>
          <el-button type="primary" @click="handleSearch" :icon="Search">
            搜索
          </el-button>
        </div>
      </template>
    </MyForm>
  </div>
</template>

<script lang="ts">
import MyForm from '@/base-ui/Form/Form.vue'
import { defineComponent, ref } from 'vue'
import { Search, Refresh } from '@element-plus/icons-vue'
export default defineComponent({
  components: {
    MyForm
  },
  props: {
    pageFormConfig: {
      type: Object,
      reuqired: true
    }
  },
  setup(props, { emit }) {
    const formItems = props.pageFormConfig?.formItems ?? []
    const formOriginData: any = {}
    for (const item of formItems) {
      formOriginData[item.field] = ''
    }
    const formData = ref(formOriginData)
    const handleReset = () => {
      formData.value = formOriginData
      emit('resetBtnClick')
    }
    const handleSearch = () => {
      emit('searchBtnClick', formData.value)
    }
    return { formData, handleSearch, handleReset, Search, Refresh }
  }
})
</script>

<style scoped lang="less">
.PageForm {
  .icon {
    width: 1em;
    height: 1em;
  }
  .footer {
    text-align: right;
    padding-bottom: 20px;
    padding-right: 10px;
  }
}
</style>
